package com.taobao.sinan.dal;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;

public class DataSource {
	private Connection conn;

	private Set<String> tables = new HashSet<String>();

	private String name;

	public DataSource(Connection conn, String name) {
		this.conn = conn;
		this.name = name;
		init();
	}

	public String getName() {
		return name;
	}

	private void init() {
		if (conn != null) {
			try {
				DatabaseMetaData data = conn.getMetaData();

				ResultSet rs = data.getTables(null, null, null, null);

				while (rs.next()) {
					tables.add(rs.getString("TABLE_NAME"));		
				}

				rs.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public Connection getConn() {
		return conn;
	}

	public Set<String> getTables() {
		return tables;
	}
}
